﻿using System.Collections.Generic;
using System.Web.Mvc;
using ChiakiYu.Model.Permissions;
using ChiakiYu.Web.Controllers.Filters;

namespace ChiakiYu.Web.Controllers
{
    [PermissionAuthorize]
    public abstract partial class BaseController : Controller
    {
        //
        // GET: /Base/

        /// <summary>
        ///     缓存key
        /// </summary>
        private const string _permissionKey = "PermissionsOfAssembly";

        /// <summary>
        ///     程序集中权限集合
        /// </summary>
        protected IEnumerable<Permission> _permissionsOfAssembly
        {
            get
            {
                var permissions = HttpContext.Application.Get(_permissionKey) as IEnumerable<Permission>;
                if (permissions == null)
                {
                    //取程序集中全部权限
                    permissions = ActionPermissionService.GetAllActionByAssembly();
                    //添加到缓存
                    HttpContext.Application.Add(_permissionKey, permissions);
                }
                return permissions;
            }
        }
    }
}